package cn.yun.web.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

/*
演示Request对象获获取请求体数据消息(post参数)
 Enumeration<>  getHeaderNames():获取请求头的所有名称 返回Enumeration对象
   String getHeader(String name):获取请求头中指定名称的数据

Enumeration:类似于迭代器
 方法: hasMoreElements():测试此枚举是否包含更多元素
          nextElement():如果此枚举对象至少有一个要提供的元素,返回此枚举的下一个元素

*/

@WebServlet("/requestDemo5")
public class RequestDemo5 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求体数据消息--请求参数
        //1.获取字符流
        BufferedReader br = request.getReader();
        //2.读取数据
        String line = null;
        while ((line = br.readLine())!= null){
            System.out.println(line);//username=zhangsan&password=1111
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}

